package com.tarena.lbs.attach.service.impl;

import com.tarena.lbs.attach.dao.repository.AttachRepository;
import com.tarena.lbs.attach.service.AttachService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AttachServiceImpl implements AttachService {
    @Autowired
    private AttachRepository attachRepository;
    @Override
    public Integer add(String fileName, String fileUrl) {
        return attachRepository.add(fileName,fileUrl);
    }

    public String getAttachUrl(String id) {
        // 添加空值检查
        if (id == null || id.trim().isEmpty()) {
            log.warn("图片ID为空");
            return null;
        }
        
        try {
            return attachRepository.getAttachUrl(id);
        } catch (Exception e) {
            log.error("获取图片URL失败，图片ID: {}", id, e);
            return null;
        }
    }
}